package com.lehoon.tomato.controller;


import com.lehoon.tomato.model.StoreGoods;
import com.lehoon.tomato.model.common.Result;
import com.lehoon.tomato.model.vo.StoreGoodsGroupVo;
import com.lehoon.tomato.model.vo.StoreGoodsVo;
import com.lehoon.tomato.service.GoodsService;
import com.lehoon.tomato.service.StoreGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  商品控制器
 * </p>
 *
 * @author wang
 * @since 2020-09-23
 */
@RestController
@RequestMapping("/auth/goods")
@Api(description = "商品相关接口")
public class GoodsController {

    @Resource
    private StoreGoodsService storeGoodsService;


    @ApiOperation(value = "店铺商品列表")
    @GetMapping("getStoreGoods")
    @ApiImplicitParam(name="storeId",value="店铺id",dataType="int", paramType = "query")
    public Result<List<StoreGoodsGroupVo>> getStoreGoods(Integer storeId){
        List<StoreGoodsGroupVo> list  = storeGoodsService.getStoreGoodsList(storeId);
        return Result.successResult(list);
    }

    @ApiOperation(value = "查看商品详情")
    @GetMapping("getGoodsDetail ")
    @ApiImplicitParam(name="goodsId",value="商品id",dataType="int", paramType = "query")
    public Result<StoreGoodsVo> getGoodsDetail(Integer goodsId){
        StoreGoods goods = storeGoodsService.getGoods(goodsId);
        StoreGoodsVo vo = new StoreGoodsVo();
        BeanUtils.copyProperties(goods,vo);
        return Result.successResult(vo);
    }
}

